package com.example.shardingspheretest.service;

import com.example.shardingspheretest.entity.User;
import com.example.shardingspheretest.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;
import org.springframework.web.bind.annotation.PostMapping;

import javax.annotation.Resource;

@Service
public class UserService {
    @Resource
    private UserMapper userMapper;
    @Autowired
    PlatformTransactionManager transactionManager;

    public void insert(User user){
        TransactionDefinition definition = new DefaultTransactionDefinition();
        TransactionStatus status = transactionManager.getTransaction(definition);
        userMapper.insert(user);
        transactionManager.commit(status);
        int i = 1/0;
    }
}
